package com.core.ui.customcell;

import com.core.utils.HTMLTagUtils;
import com.core.utils.KeyValueDictionary;
import com.core.utils.LocalizableString;

public class CustomCell {

	private Boolean selected     = false;
	private String  name;
	private String  linkURL;
	private String  onClickEvent = "javascript:void(0);";
	private String  styleClassName;
	private String  linkStyleClassName;
	private String  selectedStyleClassName;



	public String getOnClickEvent () {

		return onClickEvent;
	}



	public void setOnClickEvent ( String onClickEvent ) {

		this.onClickEvent = onClickEvent;
	}



	public Boolean getSelected () {

		return selected;
	}



	public void setSelected ( Boolean selected ) {

		this.selected = selected;
	}



	public String getName () {

		return name;
	}



	public void setName ( String name ) {

		this.name = name;
	}



	public String getLinkURL () {

		return linkURL;
	}



	public void setLinkURL ( String url ) {

		this.linkURL = url;
	}



	public String getStyleClassName () {

		return styleClassName;
	}



	public void setStyleClassName ( String styleClass ) {

		this.styleClassName = styleClass;
	}



	public String getLinkStyleClassName () {

		return linkStyleClassName;
	}



	public void setLinkStyleClassName ( String linkStyleClass ) {

		this.linkStyleClassName = linkStyleClass;
	}



	public String getSelectedStyleClassName () {

		return selectedStyleClassName;
	}



	public void setSelectedStyleClassName ( String selectedStyleClass ) {

		this.selectedStyleClassName = selectedStyleClass;
	}



	@Override
	public String toString () {

		String style = styleClassName;
		if ( selected ) {
			if ( selectedStyleClassName != null ) {
				style = style.concat(" ").concat(selectedStyleClassName);
			}
		}

		String link = (this.linkURL == null) ? "javascript:void(0);" : this.linkURL;

		KeyValueDictionary linkDictionary = new KeyValueDictionary();
		linkDictionary.put("href", String.format("\"%s\"", link));
		if ( this.onClickEvent != null ) {
			linkDictionary.put("onClick", String.format("\"%s\"", this.onClickEvent));
		}
		if ( this.linkStyleClassName != null ) {
			linkDictionary.put("class", String.format("\"%s\"", this.linkStyleClassName));
		}
		LocalizableString localizableString = LocalizableString.sharedInstance();
		String caption = localizableString.localizable(this.name);
		String formattedLink = HTMLTagUtils.customTag("a", linkDictionary, caption);

		KeyValueDictionary divDictionary = new KeyValueDictionary();
		divDictionary.put("class", String.format("\"%s\"", style));
		divDictionary.put("id", String.format("\"%s\"", this.name));
		String itemFormat = HTMLTagUtils.customTag("div", divDictionary, formattedLink);

		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(itemFormat);
		return stringBuilder.toString();
	}
}
